﻿#include "Application.h"
#include "MainWindow.h"
#include "system/crashhandler.h"
#include "system/qtloghandler.h"

#include <QDebug>

namespace Core {

	Application::Application(int &argc, char **argv)
		: QApplication(argc, argv)
		, m_pMainWindow(nullptr)
	{

	}

	Application::~Application()
	{

	}

	bool Application::initInstance()
	{
		// 注册崩溃处理功能
		Common::CrashHandler::initCrashHandler();
		// 安装消息处理函数
		Common::QtLogHandler::Get().installMessageHandler();

		qInfo() << QString("---------------------- open Application ----------------------------");

		m_pMainWindow = new MainWindow();
		m_pMainWindow->initAll();
		m_pMainWindow->show();
		return true;
	}

	void Application::exitInstance()
	{
		if (m_pMainWindow)
		{
			delete m_pMainWindow;
			m_pMainWindow = NULL;
		}

		Common::QtLogHandler::Get().uninstallMessageHandler();
	}

	MainWindow * Application::getMainWindow()
	{
		return m_pMainWindow;
	}

}//namespace Core